package nc.tb.perm.table;

import nc.tb.cube.model.FlowDefTableModel;
import nc.tb.dim.filter.DimFilter;
import nc.tb.pub.ref.DimMemberSetRefPane;
import nc.tb.pub.ref.DimPermRefPane;
import nc.ui.pub.beans.UITable;
import nc.ui.pub.bill.BillCellEditor;

public class DimPermCellEditor extends BillCellEditor {

	private UITable m_table = null;

	public DimPermCellEditor(final DimPermRefPane dmref, UITable table) {
		super(dmref);
		m_table = table;
		delegate = new EditorDelegate() {
			public void setValue(Object value) {
				dmref.setValue((value != null) ? value.toString() : "");
			}

			public Object getCellEditorValue() {
				if (dmref.getSelectedBusiObj() == null)
					return null;
				else
					return dmref.getSelectedBusiObj();
			}
		};
	}

	public java.awt.Component getTableCellEditorComponent(javax.swing.JTable table, Object value, boolean isSelected, int row, int column) {
		if (m_table != null) {
			DimDefListAssembelTableModel model = (DimDefListAssembelTableModel) m_table.getModel();
			try {
				String fe = model.getDimPerm(row);
				((DimPermRefPane) editorComponent).setSelectedBusiObj(fe);
				((DimPermRefPane) editorComponent).setIsForbidden(model.getIsForbidden(row));
			} catch (Exception e) {
				// TODO: handle exception
				//System.out.println(e.getStackTrace());
			}
		}
		delegate.setValue(value);
		return editorComponent;
	}

}
